<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        console.log("雨水问题");
        let shuisum = 0;
        let arr = [4,3,2,0,1,1,5];
        for(let j=1;j<=5;j++){
            let shui = 0;
            for(let i=0; i<arr.length; i++){
                let a = arr[i];
                if(a>j){
                    a = j;
                }
                if(a<j){
                    let i1t = false;
                    let i2t = false;
                    for(let i1=0; i1<i; i1++){
                        if(arr[i1]>=j){
                            i1t = true;
                        }
                    }
                    for(let i2=i; i2<arr.length; i2++){
                        if(arr[i2]>=j){
                            i2t = true;
                        }
                    }
                    if(i1t&&i2t){
                        console.log("第几层可以存水："+i);
                        shui ++;
                        console.log("此层雨水："+shui);
                    }
                }
            }
            shuisum += shui;
        }
        console.log(shuisum);

    </script>
</body>
</html>